<?php

class DodavanjeForm extends BaseForm {

    public function configure() {
        $max;
        $this->setWidgets(array(
            "broj" => new sfWidgetFormInput(array(), array("style" => "width:30px", "value" => "1"))
        ));

        $this->setValidators(array(
            'broj' => new sfValidatorInteger()
        ));

        $this->getWidget('broj')->setLabel('Dodaj u korpu:');
        $this->widgetSchema->setNameFormat('dodavanje[%s]');

        $this->validatorSchema->setPostValidator(
                new sfValidatorCallback(array('callback' => array($this, 'checkMax')))
        );
    }

    public function checkMax($validator, $values) {


        if ($this->max < $values['broj']) {
            $error = new sfValidatorError($validator, 'Mnogo');
            throw new sfValidatorErrorSchema($validator, array('broj' => $error));
        }



        return $values;
    }

    public function updateValidator($max) {

        $this->max = $max;
    }

}

?>
